﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

namespace SkyBase
{
    class MainMenu:Overlay
    {
        //Shall we start the game?
        private bool start = false;
        private Game1 engine;

        public MainMenu(Game1 engine):base(Storage.getTexture("BG"), "MainMenu", true)
        {
            hold = true;
            this.engine = engine;
        }

        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            //Because hold is true, whenever this overlay's update method is called
            //the game won't be running. This means that we can safely check for
            //keyboard input

            KeyboardState keyboardState = Keyboard.GetState();


            if (keyboardState.IsKeyDown(Keys.F4))
                engine.Exit();
            
            if (keyboardState.IsKeyDown(Keys.Space))
                start = true;
            
            //If the game is set to start, keep running the preRemove method until it sets readyForRemoval to true
            //We do this to get the fade out effect
            if (start)
            {
                preRemove();
            }
            
        }


        public override void reset()
        {
            start = false;
            base.reset();
        }

      
        public override void Draw(SpriteBatch spriteBatch, Vector2 cameraPos)
        {
            Texture2D tex = Storage.getTexture("Logo");
            spriteBatch.Draw(tex, new Rectangle((int)cameraPos.X + bounds.Width / 2, (int)cameraPos.Y + bounds.Height / 2, tex.Width, tex.Height), null, Color.White*alpha, 0, new Vector2(tex.Width/2, tex.Height/2), SpriteEffects.None, layer - 0.1f);

            spriteBatch.DrawString(Storage.getFont("Arial"), "Press Space to start and F4 to quit! Escape opens this page!", new Vector2((int)cameraPos.X - 200 + bounds.Width / 2, (int)cameraPos.Y + bounds.Height*2/3), Color.Black*alpha);

            base.Draw(spriteBatch, cameraPos);
        }
    }
}
